﻿using System;

using Google.GData.Photos;

namespace SBPweb.DNN.Picasa
{

    public class Client
    {

        #region Private fields

        private PicasaService pService;
        private string pAuthToken;
        private string pUserName;

        #endregion

        #region Constructor logic

        public Client(string userName, string password)
            : this(Guid.NewGuid(), userName, password)
        {
        }

        public Client(Guid id, string userName, string password)
        {
            pService = new PicasaService(string.Format("SBPweb.DNN.Picasa.{0}", id));
            SetCredentials(userName, password);
        }

        #endregion

        #region Property accessors

        public string UserName
        {
            get
            {
                return pUserName;
            }
        }

        #endregion

        #region Methods

        public void SetCredentials(string userName, string password)
        {
            pUserName = userName;
            pService.setUserCredentials(userName, password);
        }

        public bool Authenticate()
        {
            try
            {
                pAuthToken = pService.QueryAuthenticationToken();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public void s()
        {
            AlbumQuery query = new AlbumQuery();

            query.Uri = new Uri(PicasaQuery.CreatePicasaUri(pUserName));

            PicasaFeed feed = pService.Query(query);
            /*
            if (this.picasaFeed != null && this.picasaFeed.Entries.Count > 0)
            {
                foreach (PicasaEntry entry in this.picasaFeed.Entries)
                {
                    ListViewItem item = new ListViewItem(entry.Title.Text +
                                    " (" + entry.getPhotoExtensionValue(GPhotoNameTable.NumPhotos) + " )");
                    item.Tag = entry;
                    this.AlbumList.Items.Add(item);
                }
            }
            this.AlbumList.Update();
            */
        }

        #endregion

    }

}